package com.hongxun.budget.utils;

import android.content.Context;
import android.text.TextUtils;

import com.hongxun.budget.R;
import com.hongxun.budget.greendao.BDeviceEntityDao;
import com.hongxun.budget.greendao.BMaterialEntityDao;
import com.hongxun.budget.greendao.CArrivalRecordEntityDao;
import com.hongxun.budget.greendao.CBasicsWorkEntityDao;
import com.hongxun.budget.greendao.CGoodsDetailEntityDao;
import com.hongxun.budget.greendao.CGroundEntityDao;
import com.hongxun.budget.greendao.CLinePitEntityDao;
import com.hongxun.budget.greendao.CMiddleCheckEntityDao;
import com.hongxun.budget.greendao.CPBaseEntityDao;
import com.hongxun.budget.greendao.CPolePitEntityDao;
import com.hongxun.budget.greendao.CScheduleEntityDao;
import com.hongxun.budget.greendao.CScheduleReportEntityDao;
import com.hongxun.budget.greendao.CStackPointEntityDao;
import com.hongxun.budget.greendao.DPictureEntityDao;
import com.hongxun.entity.sg.CYbgcInfo;
import com.hongxun.greenentity.sg.CArrivalRecordEntity;
import com.hongxun.greenentity.sg.CBasicsWorkEntity;
import com.hongxun.greenentity.sg.CGoodsDetailEntity;
import com.hongxun.greenentity.sg.CGroundEntity;
import com.hongxun.greenentity.sg.CLinePitEntity;
import com.hongxun.greenentity.sg.CMiddleCheckEntity;
import com.hongxun.greenentity.sg.CPBaseEntity;
import com.hongxun.greenentity.sg.CPolePitEntity;
import com.hongxun.greenentity.sg.CScheduleEntity;
import com.hongxun.greenentity.sg.CScheduleReportEntity;
import com.hongxun.greenentity.sg.CStackPointEntity;
import com.hongxun.greenentity.tk.BDeviceEntity;
import com.hongxun.greenentity.tk.BMaterialEntity;
import com.hongxun.greenentity.tk.DPictureEntity;
import com.hongxun.net.Contants;

import org.greenrobot.greendao.query.WhereCondition;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

public class SgDBUtils {
    //------------------new------------------//

    /**
     * 依据施工项目状态
     * true：删除
     * false：非删除
     * 查找施工项目
     */
    public static List<CPBaseEntity> getCPBaseList(boolean isDel) {
        WhereCondition eq1;
        if (isDel) {
            eq1 = CPBaseEntityDao.Properties.PBDatastate.eq(SgStrKey.del);
        } else {
            eq1 = CPBaseEntityDao.Properties.PBDatastate.notEq(SgStrKey.del);
        }
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCPBaseEntityDao()
                .queryBuilder()
                .orderDesc(CPBaseEntityDao.Properties.PBAddtime)
                .where(eq1)
                .list();
    }

    /**
     * 依据项目guid，mode
     * 获取施工自检条数
     * 或
     * 获取现场自检条数
     */
    public static int getZjjcCount(String guid, String mode) {
        return getCMceList(guid, mode).size();
    }

    //依据项目guid获取材料堆放点数量

    /**
     * 依据项目guid
     * 获取材料堆放点数量
     */
    public static int getCldcDfdCount(String guid) {
        return getCSpListAll(guid).size();
    }

    //依据项目id获取施工进度

    /**
     * 依据项目id获取施工进度数据
     */
    public static List<CScheduleEntity> getScheduleAll(String PGuid) {
        WhereCondition eq1 = CScheduleEntityDao.Properties.PGuid.eq(PGuid);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCScheduleEntityDao()
                .queryBuilder()
                .orderDesc(CScheduleEntityDao.Properties.SSort)
                .where(eq1)
                .list();
    }

    public static CScheduleEntity getScheduleSort(String PGuid, String SName) {
        WhereCondition eq1 = CScheduleEntityDao.Properties.PGuid.eq(PGuid);
        WhereCondition eq2 = CScheduleEntityDao.Properties.SName.eq(SName);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCScheduleEntityDao()
                .queryBuilder()
                .where(eq1, eq2)
                .unique();
    }

    //依据项目id和进度名称更新施工进度

    /**
     * 依据项目id和进度名称更新施工进度数据
     */
    public static void updateCSEntity(Context context, String pguid, String sname) {
        CScheduleEntity scheduleEntity = getScheduleSort(pguid, sname);
        scheduleEntity.setSTime(new Date(System.currentTimeMillis()));
        GreenDaoManager.getInstance().getmDaoSession()
                .getCScheduleEntityDao()
                .update(scheduleEntity);
        SPUtils.put(context, SgStrKey.uuidjd, scheduleEntity.getGuid());
    }

    //施工进度：删除

    /**
     * 施工进度：删除
     */
    public static void delCScheduleEntity(String guid) {
        CScheduleEntity unique = getCSchedule(guid);
        CScheduleEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCScheduleEntityDao();
        if (unique != null) {
            if (unique.getSDatastate().equals(SgStrKey.add)) {
                entityDao.delete(unique);
            } else {
                unique.setSDatastate(SgStrKey.del);
                entityDao.update(unique);
            }
            List<CScheduleReportEntity> list = getCSrListAll(guid);
            for (CScheduleReportEntity entity : list) {
                delCScheduleReportEntity(entity.getGuid());
            }
        }
    }

    //施工进度填报记录：删除

    /**
     * 施工进度填报记录：删除
     */
    public static void delCScheduleReportEntity(String guid) {
        CScheduleReportEntity unique = getCScheduleReport(guid);
        CScheduleReportEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCScheduleReportEntityDao();
        if (unique != null) {
            if (unique.getSRDatastate().equals(SgStrKey.add)) {
                entityDao.delete(unique);
            } else {
                unique.setSRDatastate(SgStrKey.del);
                entityDao.update(unique);
            }
        }
    }

    //施工进度填报记录：更新

    /**
     * 施工进度填报记录：更新
     */
    public static void upDateCScheduleReportEntity(CScheduleReportEntity entity) {
        CScheduleReportEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCScheduleReportEntityDao();
        CScheduleReportEntity unique = getCScheduleReport(entity.getGuid());
        if (unique == null) {
            entityDao.insert(entity);
        } else {
            if (entity.getSRDatastate().equals(SgStrKey.ytb)) entity.setSRDatastate(SgStrKey.xg);
            entityDao.update(entity);
        }
    }

    //施工进度填报记录

    /**
     * 施工进度填报记录
     */
    public static CScheduleReportEntity getCScheduleReport(String guid) {
        WhereCondition eq1 = CScheduleReportEntityDao.Properties.Guid.eq(guid);
        WhereCondition eq3 = CScheduleReportEntityDao.Properties.SRDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCScheduleReportEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .unique();
    }

    //依据施工进度记录id获取附属填报记录

    /**
     * 依据施工进度记录id获取附属填报记录
     */
    public static List<CScheduleReportEntity> getCScheduleReportAll(String guid) {
        WhereCondition eq1 = CScheduleReportEntityDao.Properties.SGuid.eq(guid);
        WhereCondition eq3 = CScheduleReportEntityDao.Properties.SRDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCScheduleReportEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .orderDesc(CScheduleReportEntityDao.Properties.SRUpdatetime)//降序
                .list();
    }

    //施工进度

    /**
     * 施工进度
     */
    public static CScheduleEntity getCSchedule(String guid) {
        WhereCondition eq1 = CScheduleEntityDao.Properties.Guid.eq(guid);
        WhereCondition eq3 = CScheduleEntityDao.Properties.SDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCScheduleEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .unique();
    }


    //依据项目进度id获取施工进度记录

    /**
     * 依据项目进度id获取施工进度记录
     */
    public static List<CScheduleReportEntity> getCSrListAll(String guid) {
        WhereCondition eq1 = CScheduleReportEntityDao.Properties.SGuid.eq(guid);
        WhereCondition eq3 = CScheduleReportEntityDao.Properties.SRDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCScheduleReportEntityDao()
                .queryBuilder()
                .orderDesc(CScheduleReportEntityDao.Properties.SRUpdatetime)//降序
                .where(eq1, eq3)
                .list();
    }

    //获取进度最新照片
    public static Object getJdUrl(String guid) {
        List<CScheduleReportEntity> list = getCSrListAll(guid);
        if (list == null || list.isEmpty()) return R.drawable.ic_default_image;
        return getSsUrl(list.get(0).getGuid());
    }

    //获取进度最新照片
    public static Object getYbgcUrl(String uuidjl) {
        List<CYbgcInfo> beanList = new ArrayList<>();
        List<CBasicsWorkEntity> list1 = getCBasicsWorkList(uuidjl);
        if (list1 != null && !list1.isEmpty()) {
            CYbgcInfo info = new CYbgcInfo();
            info.setUuid(list1.get(0).getGuid());
            info.setTimeAdd(list1.get(0).getBWAddtime().getTime());
            beanList.add(info);
        }
        List<CGroundEntity> list2 = getCGroundList(uuidjl);
        if (list2 != null && !list2.isEmpty()) {
            CYbgcInfo info = new CYbgcInfo();
            info.setUuid(list2.get(0).getGuid());
            info.setTimeAdd(list2.get(0).getGAddtime().getTime());
            beanList.add(info);
        }
        List<CPolePitEntity> list3 = getCPolePitList(uuidjl);
        if (list3 != null && !list3.isEmpty()) {
            CYbgcInfo info = new CYbgcInfo();
            info.setUuid(list3.get(0).getGuid());
            info.setTimeAdd(list3.get(0).getPPAddtime().getTime());
            beanList.add(info);
        }
        List<CLinePitEntity> list4 = getCLinePitList(uuidjl);
        if (list4 != null && !list4.isEmpty()) {
            CYbgcInfo info = new CYbgcInfo();
            info.setUuid(list4.get(0).getGuid());
            info.setTimeAdd(list4.get(0).getLPAddtime().getTime());
            beanList.add(info);
        }
        //依据添加时间排序
        Collections.sort(beanList, new Comparator<CYbgcInfo>() {
            @Override
            public int compare(CYbgcInfo o1, CYbgcInfo o2) {
                if (o1.getTimeAdd() < o2.getTimeAdd()) {
                    return 1;
                } else if (o1.getTimeAdd() == o2.getTimeAdd()) {
                    return 0;
                }
                return -1;
            }
        });
        if (beanList == null || beanList.isEmpty()) return R.drawable.ic_default_image;
        return getSsUrl(beanList.get(0).getUuid());
    }


    //依据项目guid获取物资堆放点数据

    /**
     * 依据项目guid
     * 获取物资堆放点数据
     */
    public static List<CStackPointEntity> getCSpListAll(String guid) {
        WhereCondition eq1 = CStackPointEntityDao.Properties.PGuid.eq(guid);
        WhereCondition eq3 = CStackPointEntityDao.Properties.SPDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCStackPointEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .list();
    }

    //依据堆放点guid获取到货记录

    /**
     * 依据堆放点guid
     * 获取到货记录
     */
    public static List<CArrivalRecordEntity> getCArListAll(String SPGuid) {
        WhereCondition eq1 = CArrivalRecordEntityDao.Properties.SPGuid.eq(SPGuid);
        WhereCondition eq3 = CArrivalRecordEntityDao.Properties.ARDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCArrivalRecordEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .list();
    }

    /**
     * 依据项目guid
     * 获取到货记录
     */
    public static List<CArrivalRecordEntity> getCArListByPGuid(String PGuid) {
        WhereCondition eq1 = CArrivalRecordEntityDao.Properties.PGuid.eq(PGuid);
        WhereCondition eq3 = CArrivalRecordEntityDao.Properties.ARDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCArrivalRecordEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .orderDesc(CArrivalRecordEntityDao.Properties.ARTime)
                .list();
    }

    //依据到货记录guid获取到货物资

    /**
     * 依据到货记录guid
     * 获取到货物资
     */
    public static List<CGoodsDetailEntity> getCGdListAll(String guid) {
        WhereCondition eq1 = CGoodsDetailEntityDao.Properties.ARGuid.eq(guid);
        WhereCondition eq3 = CGoodsDetailEntityDao.Properties.GDDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCGoodsDetailEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .list();
    }


    //依据到货记录guid获取到货物资统计信息

    /**
     * 依据到货记录guid
     * 获取到货物资统计信息
     */
    public static String getCGdListTj(String guid) {
        List<CGoodsDetailEntity> list = getCGdListAll(guid);
        List<String> listName = new ArrayList<>();
        for (CGoodsDetailEntity entity : list) {
            if (!listName.contains(entity.getGDBigtype())) {
                listName.add(entity.getGDBigtype());
            }
        }
        StringBuffer buffer = new StringBuffer();
        for (String s : listName) {
//            buffer.append(s).append("(").append(getCGdListByType(guid, s).size()).append(")");
            buffer.append(s).append("、");
        }
        return buffer.toString();
    }

    //到货记录：删除

    /**
     * 到货记录：删除
     */
    public static void delCArrivalRecordEntity(String guid) {
        CArrivalRecordEntity unique = getCArrivalRecord(guid);
        CArrivalRecordEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCArrivalRecordEntityDao();
        if (unique != null) {
            if (unique.getARDatastate().equals(SgStrKey.add)) {
                entityDao.delete(unique);
            } else {
                unique.setARDatastate(SgStrKey.del);
                entityDao.update(unique);
            }
            //删除到货物资
            List<CGoodsDetailEntity> list = getCGdListAll(guid);
            for (CGoodsDetailEntity entity : list) {
                delCGoodsDetailEntity(entity.getGuid());
            }
            //删除照片
            delDPictureEntityByPpguid(unique.getGuid());
        }
    }

    //获取到货记录

    /**
     * 获取到货记录
     */
    public static CArrivalRecordEntity getCArrivalRecord(String guid) {
        WhereCondition eq1 = CArrivalRecordEntityDao.Properties.Guid.eq(guid);
        WhereCondition eq3 = CArrivalRecordEntityDao.Properties.ARDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCArrivalRecordEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .unique();
    }


    //到货记录：更新/插入

    /**
     * 到货记录：更新/插入
     */
    public static void upDataCArrivalRecordEntity(CArrivalRecordEntity entity) {
        CArrivalRecordEntity unique = getCArrivalRecord(entity.getGuid());
        CArrivalRecordEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCArrivalRecordEntityDao();
        if (unique == null) {
            entityDao.insert(entity);
        } else {
            if (entity.getARDatastate().equals(SgStrKey.ytb)) entity.setARDatastate(SgStrKey.xg);
            entityDao.update(entity);
        }
    }

    //到货物资：删除

    /**
     * 到货物资：删除
     */
    public static void delCGoodsDetailEntity(String guid) {
        CGoodsDetailEntity unique = getCGoodsDetail(0, guid);
        CGoodsDetailEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCGoodsDetailEntityDao();
        if (unique != null) {
            if (unique.getGDDatastate().equals(SgStrKey.add)) {
                entityDao.delete(unique);
            } else {
                unique.setGDDatastate(SgStrKey.del);
                entityDao.update(unique);
            }
        }
    }

    //到货物资：更新/插入

    /**
     * 到货物资：更新/插入
     */
    public static void upDataCGoodsDetailEntity(int type, CGoodsDetailEntity entity) {
        CGoodsDetailEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCGoodsDetailEntityDao();
        if (type == 0) {
            CGoodsDetailEntity unique = getCGoodsDetail(0, entity.getGuid());
            if (unique == null) {
                entityDao.insert(entity);
            } else {
                if (entity.getGDDatastate().equals(SgStrKey.ytb))
                    entity.setGDDatastate(SgStrKey.xg);
                entityDao.update(entity);
            }
        } else if (type == 1) {
            CGoodsDetailEntity unique = getCGoodsDetail(1, entity.getARGuid(), entity.getMDGuid());
            if (unique == null) {
                entityDao.insert(entity);
            } else {
                if (entity.getGDDatastate().equals(SgStrKey.ytb))
                    entity.setGDDatastate(SgStrKey.xg);
                entity.setGuid(unique.getGuid());
                entity.setGDNum(entity.getGDNum() + unique.getGDNum());
                entityDao.update(entity);
            }
        }
    }

    //到货物资

    /**
     * 到货物资
     */
    public static CGoodsDetailEntity getCGoodsDetail(int type, Object... value) {
        CGoodsDetailEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCGoodsDetailEntityDao();
        if (type == 0) {
            WhereCondition eq1 = CGoodsDetailEntityDao.Properties.Guid.eq(value[0]);
            WhereCondition eq3 = CGoodsDetailEntityDao.Properties.GDDatastate.notEq(SgStrKey.del);
            CGoodsDetailEntity unique = entityDao.queryBuilder().where(eq1, eq3).unique();
            return unique;
        } else if (type == 1) {
            WhereCondition eq1 = CGoodsDetailEntityDao.Properties.ARGuid.eq(value[0]);
            WhereCondition eq2 = CGoodsDetailEntityDao.Properties.MDGuid.eq(value[1]);
            WhereCondition eq3 = CGoodsDetailEntityDao.Properties.GDDatastate.notEq(SgStrKey.del);
            CGoodsDetailEntity unique = entityDao.queryBuilder().where(eq1, eq2, eq3).unique();
            return unique;
        }
        return null;
    }


    /**
     * 依据项目guid，mode
     * 获取施工自检数据
     * 或
     * 获取现场自检数据
     */
    public static List<CMiddleCheckEntity> getCMceList(String guid, String mode) {
        WhereCondition eq1 = CMiddleCheckEntityDao.Properties.PGuid.eq(guid);
        WhereCondition eq2 = CMiddleCheckEntityDao.Properties.MCMode.eq(mode);
        WhereCondition eq3 = CMiddleCheckEntityDao.Properties.MCDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCMiddleCheckEntityDao()
                .queryBuilder()
                .where(eq1, eq2, eq3)
                .orderDesc(CMiddleCheckEntityDao.Properties.MCTime)//降序
                .list();
    }

    /**
     * 依据项目guid
     * 获取施工自检数据
     * 和
     * 获取现场自检数据
     */
    public static List<CMiddleCheckEntity> getCMceListAll(String guid) {
        WhereCondition eq1 = CMiddleCheckEntityDao.Properties.PGuid.eq(guid);
        WhereCondition eq3 = CMiddleCheckEntityDao.Properties.MCDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCMiddleCheckEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .orderDesc(CMiddleCheckEntityDao.Properties.MCTime)//降序
                .list();
    }


    //获取隐蔽工程记录：电杆坑数据

    /**
     * 获取隐蔽工程记录：电杆坑数据
     */
    public static List<CPolePitEntity> getCPolePitList(String guid) {
        WhereCondition eq1 = CPolePitEntityDao.Properties.MCGuid.eq(guid);
        WhereCondition eq3 = CPolePitEntityDao.Properties.PPDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCPolePitEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .orderDesc(CPolePitEntityDao.Properties.PPAddtime)//降序
                .list();
    }

    //获取项目全部杆塔坑数据

    /**
     * 获取项目全部杆塔坑数据
     */
    public static List<CPolePitEntity> getPolePitAll(String MCGuid) {
        WhereCondition eq1 = CPolePitEntityDao.Properties.MCGuid.eq(MCGuid);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCPolePitEntityDao()
                .queryBuilder()
                .where(eq1)
                .orderDesc(CPolePitEntityDao.Properties.PPAddtime)//降序
                .list();
    }

    //获取电杆坑数据

    /**
     * 获取电杆坑数据
     */
    public static CPolePitEntity getCPolePit(String guid) {
        WhereCondition eq1 = CPolePitEntityDao.Properties.Guid.eq(guid);
        WhereCondition eq3 = CPolePitEntityDao.Properties.PPDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCPolePitEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .unique();
    }

    //电杆坑：更新/插入

    /**
     * 电杆坑：更新/插入
     */
    public static void upDataCPolePitEntity(CPolePitEntity entity) {
        CPolePitEntity unique = getCPolePit(entity.getGuid());
        CPolePitEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCPolePitEntityDao();
        if (unique == null) {
            entityDao.insert(entity);
        } else {
            if (entity.getPPDatastate().equals(SgStrKey.ytb)) entity.setPPDatastate(SgStrKey.xg);
            entityDao.update(entity);
        }
    }

    //电杆坑：删除

    /**
     * 电杆坑：删除
     */
    public static void delCPolePitEntity(String guid) {
        CPolePitEntity unique = getCPolePit(guid);
        CPolePitEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCPolePitEntityDao();
        if (unique != null) {
            if (unique.getPPDatastate().equals(SgStrKey.add)) {
                entityDao.delete(unique);
            } else {
                unique.setPPDatastate(SgStrKey.del);
                entityDao.update(unique);
            }
        }
    }

    //获取隐蔽工程记录：拉线坑数据

    /**
     * 获取隐蔽工程记录：拉线坑数据
     */
    public static List<CLinePitEntity> getCLinePitList(String guid) {
        WhereCondition eq1 = CLinePitEntityDao.Properties.MCGuid.eq(guid);
        WhereCondition eq3 = CLinePitEntityDao.Properties.LPDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCLinePitEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .orderDesc(CLinePitEntityDao.Properties.LPAddtime)//降序
                .list();
    }

    //获取项目全部拉线坑数据

    /**
     * 获取项目全部拉线坑数据
     */
    public static List<CLinePitEntity> getLinePitAll(String MCGuid) {
        WhereCondition eq1 = CLinePitEntityDao.Properties.MCGuid.eq(MCGuid);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCLinePitEntityDao()
                .queryBuilder()
                .where(eq1)
                .orderDesc(CLinePitEntityDao.Properties.LPAddtime)//降序
                .list();
    }

    //获取拉线坑数据

    /**
     * 获取拉线坑数据
     */
    public static CLinePitEntity getCLinePit(String guid) {
        WhereCondition eq1 = CLinePitEntityDao.Properties.Guid.eq(guid);
        WhereCondition eq3 = CLinePitEntityDao.Properties.LPDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCLinePitEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .unique();
    }

    //拉线坑：更新/插入

    /**
     * 拉线坑：更新/插入
     */
    public static void upDataCLinePitEntity(CLinePitEntity entity) {
        CLinePitEntity unique = getCLinePit(entity.getGuid());
        CLinePitEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCLinePitEntityDao();
        if (unique == null) {
            entityDao.insert(entity);
        } else {
            if (entity.getLPDatastate().equals(SgStrKey.ytb)) entity.setLPDatastate(SgStrKey.xg);
            entityDao.update(entity);
        }
    }

    //拉线坑：删除

    /**
     * 拉线坑：删除
     */
    public static void delCLinePitEntity(String guid) {
        CLinePitEntity unique = getCLinePit(guid);
        CLinePitEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCLinePitEntityDao();
        if (unique != null) {
            if (unique.getLPDatastate().equals(SgStrKey.add)) {
                entityDao.delete(unique);
            } else {
                unique.setLPDatastate(SgStrKey.del);
                entityDao.update(unique);
            }
        }
    }

    //获取隐蔽工程记录：接地体数据

    /**
     * 获取隐蔽工程记录：接地体数据
     */
    public static List<CGroundEntity> getCGroundList(String guid) {
        WhereCondition eq1 = CGroundEntityDao.Properties.MCGuid.eq(guid);
        WhereCondition eq3 = CGroundEntityDao.Properties.GDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCGroundEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .orderDesc(CGroundEntityDao.Properties.GAddtime)//降序
                .list();
    }

    //获取项目全部接地体数据

    /**
     * 获取项目全部接地体数据
     */
    public static List<CGroundEntity> getGroundAll(String MCGuid) {
        WhereCondition eq1 = CGroundEntityDao.Properties.MCGuid.eq(MCGuid);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCGroundEntityDao()
                .queryBuilder()
                .where(eq1)
                .orderDesc(CGroundEntityDao.Properties.GAddtime)//降序
                .list();
    }

    //获取接地体数据

    /**
     * 获取接地体数据
     */
    public static CGroundEntity getCGround(String guid) {
        WhereCondition eq1 = CGroundEntityDao.Properties.Guid.eq(guid);
        WhereCondition eq3 = CGroundEntityDao.Properties.GDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCGroundEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .unique();
    }

    //接地体：更新/插入

    /**
     * 接地体：更新/插入
     */
    public static void upDataCGroundEntity(CGroundEntity entity) {
        CGroundEntity unique = getCGround(entity.getGuid());
        CGroundEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCGroundEntityDao();
        if (unique == null) {
            entityDao.insert(entity);
        } else {
            if (entity.getGDatastate().equals(SgStrKey.ytb)) entity.setGDatastate(SgStrKey.xg);
            entityDao.update(entity);
        }
    }

    //接地体：删除

    /**
     * 接地体：删除
     */
    public static void delCGroundEntity(String guid) {
        CGroundEntity unique = getCGround(guid);
        CGroundEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCGroundEntityDao();
        if (unique != null) {
            if (unique.getGDatastate().equals(SgStrKey.add)) {
                entityDao.delete(unique);
            } else {
                unique.setGDatastate(SgStrKey.del);
                entityDao.update(unique);
            }
        }
    }

    //获取隐蔽工程记录：设备基础数据

    /**
     * 获取隐蔽工程记录：设备基础数据
     */
    public static List<CBasicsWorkEntity> getCBasicsWorkList(String guid) {
        WhereCondition eq1 = CBasicsWorkEntityDao.Properties.MCGuid.eq(guid);
        WhereCondition eq3 = CBasicsWorkEntityDao.Properties.BWDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCBasicsWorkEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .orderDesc(CBasicsWorkEntityDao.Properties.BWAddtime)//降序
                .list();
    }

    //获取项目全部设备基础数据

    /**
     * 获取项目全部设备基础数据
     */
    public static List<CBasicsWorkEntity> getBasicsWorkAll(String MCGuid) {
        WhereCondition eq1 = CBasicsWorkEntityDao.Properties.MCGuid.eq(MCGuid);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCBasicsWorkEntityDao()
                .queryBuilder()
                .where(eq1)
                .orderDesc(CBasicsWorkEntityDao.Properties.BWAddtime)//降序
                .list();
    }

    //获取设备基础数据

    /**
     * 获取设备基础数据
     */
    public static CBasicsWorkEntity getCBasicsWork(String guid) {
        WhereCondition eq1 = CBasicsWorkEntityDao.Properties.Guid.eq(guid);
        WhereCondition eq3 = CBasicsWorkEntityDao.Properties.BWDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCBasicsWorkEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .unique();
    }

    //设备基础：更新/插入

    /**
     * 设备基础：更新/插入
     */
    public static void upDataCBasicsWorkEntity(CBasicsWorkEntity entity) {
        CBasicsWorkEntity unique = getCBasicsWork(entity.getGuid());
        CBasicsWorkEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCBasicsWorkEntityDao();
        if (unique == null) {
            entityDao.insert(entity);
        } else {
            if (entity.getBWDatastate().equals(SgStrKey.ytb)) entity.setBWDatastate(SgStrKey.xg);
            entityDao.update(entity);
        }
    }

    //设备基础：删除

    /**
     * 设备基础：删除
     */
    public static void delCBasicsWorkEntity(String guid) {
        CBasicsWorkEntity unique = getCBasicsWork(guid);
        CBasicsWorkEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCBasicsWorkEntityDao();
        if (unique != null) {
            if (unique.getBWDatastate().equals(SgStrKey.add)) {
                entityDao.delete(unique);
            } else {
                unique.setBWDatastate(SgStrKey.del);
                entityDao.update(unique);
            }
        }
    }

    //删除隐蔽工程记录

    /**
     * 删除隐蔽工程记录
     */
    public static void deleteCMiddleCheckEntity(String uuid) {
        WhereCondition eq1 = CMiddleCheckEntityDao.Properties.Guid.eq(uuid);
        WhereCondition eq3 = CMiddleCheckEntityDao.Properties.MCDatastate.notEq(SgStrKey.del);

        CMiddleCheckEntityDao dao = GreenDaoManager.getInstance().getmDaoSession().getCMiddleCheckEntityDao();
        CMiddleCheckEntity unique = dao.queryBuilder().where(eq1, eq3).unique();
        if (unique != null) {
            if (unique.getMCDatastate().equals(SgStrKey.add)) {
                dao.delete(unique);
            } else {
                unique.setMCDatastate(SgStrKey.del);
                dao.update(unique);
            }
            delCPolePit(uuid);
            delCLinePit(uuid);
            delCGround(uuid);
            delCBasicsWork(uuid);
        }
    }

    //删除隐蔽工程记录下-电杆坑

    /**
     * 删除隐蔽工程记录下-电杆坑
     */
    public static void delCPolePit(String guid) {
        WhereCondition eq1 = CPolePitEntityDao.Properties.MCGuid.eq(guid);
        WhereCondition eq3 = CPolePitEntityDao.Properties.PPDatastate.notEq(SgStrKey.del);
        CPolePitEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCPolePitEntityDao();
        List<CPolePitEntity> list = entityDao.queryBuilder().where(eq1, eq3).list();
        if (list == null) return;
        for (CPolePitEntity unique : list) {
            if (unique.getPPDatastate().equals(SgStrKey.add)) {
                entityDao.delete(unique);
            } else {
                unique.setPPDatastate(SgStrKey.del);
                entityDao.update(unique);
            }
            //删除照片
            delDPictureEntityByPpguid(unique.getGuid());
        }
    }

    //删除隐蔽工程记录下-拉线坑

    /**
     * 删除隐蔽工程记录下-拉线坑
     */
    public static void delCLinePit(String guid) {
        WhereCondition eq1 = CLinePitEntityDao.Properties.MCGuid.eq(guid);
        WhereCondition eq3 = CLinePitEntityDao.Properties.LPDatastate.notEq(SgStrKey.del);
        CLinePitEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCLinePitEntityDao();
        List<CLinePitEntity> list = entityDao.queryBuilder().where(eq1, eq3).list();
        if (list == null) return;
        for (CLinePitEntity unique : list) {
            if (unique.getLPDatastate().equals(SgStrKey.add)) {
                entityDao.delete(unique);
            } else {
                unique.setLPDatastate(SgStrKey.del);
                entityDao.update(unique);
            }
            //删除照片
            delDPictureEntityByPpguid(unique.getGuid());
        }
    }

    //删除隐蔽工程记录下-接地体

    /**
     * 删除隐蔽工程记录下-接地体
     */
    public static void delCGround(String guid) {
        WhereCondition eq1 = CGroundEntityDao.Properties.MCGuid.eq(guid);
        WhereCondition eq3 = CGroundEntityDao.Properties.GDatastate.notEq(SgStrKey.del);
        CGroundEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCGroundEntityDao();
        List<CGroundEntity> list = entityDao.queryBuilder().where(eq1, eq3).list();
        if (list == null) return;
        for (CGroundEntity unique : list) {
            if (unique.getGDatastate().equals(SgStrKey.add)) {
                entityDao.delete(unique);
            } else {
                unique.setGDatastate(SgStrKey.del);
                entityDao.update(unique);
            }
            //删除照片
            delDPictureEntityByPpguid(unique.getGuid());
        }
    }

    //删除隐蔽工程记录下-设备基础

    /**
     * 删除隐蔽工程记录下-设备基础
     */
    public static void delCBasicsWork(String guid) {
        WhereCondition eq1 = CBasicsWorkEntityDao.Properties.MCGuid.eq(guid);
        WhereCondition eq3 = CBasicsWorkEntityDao.Properties.BWDatastate.notEq(SgStrKey.del);
        CBasicsWorkEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCBasicsWorkEntityDao();
        List<CBasicsWorkEntity> list = entityDao.queryBuilder().where(eq1, eq3).list();
        if (list == null) return;
        for (CBasicsWorkEntity unique : list) {
            if (unique.getBWDatastate().equals(SgStrKey.add)) {
                entityDao.delete(unique);
            } else {
                unique.setBWDatastate(SgStrKey.del);
                entityDao.update(unique);
            }
            //删除照片
            delDPictureEntityByPpguid(unique.getGuid());
        }
    }

    //获取隐蔽工程记录

    /**
     * 获取隐蔽工程记录
     */
    public static CMiddleCheckEntity getCMiddleCheckEntity(String guid) {
        WhereCondition eq1 = CMiddleCheckEntityDao.Properties.Guid.eq(guid);
        WhereCondition eq3 = CMiddleCheckEntityDao.Properties.MCDatastate.notEq(SgStrKey.del);
        CMiddleCheckEntity unique = GreenDaoManager.getInstance().getmDaoSession()
                .getCMiddleCheckEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .unique();
        return unique;
    }

    //隐蔽工程采集记录：更新/插入

    /**
     * 隐蔽工程采集记录：更新/插入
     */
    public static void upDataCMiddleCheckEntity(CMiddleCheckEntity entity) {
        CMiddleCheckEntity unique = getCMiddleCheckEntity(entity.getGuid());
        CMiddleCheckEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getCMiddleCheckEntityDao();
        if (unique == null) {
            entityDao.insert(entity);
        } else {
            if (entity.getMCDatastate().equals(SgStrKey.ytb)) entity.setMCDatastate(SgStrKey.xg);
            entityDao.update(entity);
        }
    }

    //获取现场、资料、图纸、清单照片

    /**
     * 获取现场、资料、图纸、清单照片
     */
    public static List<DPictureEntity> getDPictureList(String pGuid, String pPGuid, String pLabel) {
        WhereCondition eq1 = DPictureEntityDao.Properties.PGuid.eq(pGuid);
        WhereCondition eq2 = DPictureEntityDao.Properties.PPGuid.eq(pPGuid);
        WhereCondition eq3 = DPictureEntityDao.Properties.PLabel.eq(pLabel);
        WhereCondition eq4 = DPictureEntityDao.Properties.PDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getDPictureEntityDao()
                .queryBuilder()
                .where(eq1, eq2, eq3, eq4)
                .orderDesc(DPictureEntityDao.Properties.PTime)//降序
                .list();
    }


    //获取所属最新照片

    /**
     * 获取所属最新照片
     */
    public static Object getSsUrl(String ppguid) {
        List<DPictureEntity> list = getDPictureEntityList(ppguid);
        if (list == null || list.isEmpty()) {
            return R.drawable.ic_default_image;
        } else {
            return getUrl(list.get(0));
        }
    }

    /**
     * 照片路径
     */
    public static Object getUrl(DPictureEntity entity) {
        if (TextUtils.isEmpty(entity.getPServeraddress())) {
            return entity.getPAppaddress();
        } else {
            if (new File(entity.getPAppaddress()).exists()) {
                return entity.getPAppaddress();
            } else {
                return Contants.baseUrl + Contants.showPic + entity.getPServeraddress();
            }
        }
    }

    //照片：插入

    /**
     * 照片：插入
     */
    public static void upDataDPictureEntity(DPictureEntity entity) {
        if (!StringUtils.getNull(entity.getPDatastate()).equals(SgStrKey.ytb)) {
            GreenDaoManager.getInstance().getmDaoSession().getDPictureEntityDao().insertOrReplace(entity);
        }
    }

    //照片：依据ppguid删除

    /**
     * 照片：依据ppguid删除
     */
    public static void delDPictureEntityByPpguid(String ppguid) {
        List<DPictureEntity> list = getDPictureEntityList(ppguid);
        if (list == null || list.isEmpty()) return;
        for (DPictureEntity unique : list) {
            delDPictureEntity(unique);
        }
    }

    //照片：删除

    /**
     * 照片：删除
     */
    public static void delDPictureEntity(DPictureEntity unique) {
        DPictureEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getDPictureEntityDao();
        if (unique.getPDatastate().equals(SgStrKey.add)) {
            entityDao.delete(unique);
        } else {
            if (unique.getPDatastate().equals(SgStrKey.ytb))
                unique.setPDatastate(SgStrKey.del);
            entityDao.update(unique);
        }
    }

    //获取所属照片数据以时间逆序
    public static List<DPictureEntity> getDPictureEntityList(String ppguid) {
        WhereCondition eq1 = DPictureEntityDao.Properties.PPGuid.eq(ppguid);
        WhereCondition eq3 = DPictureEntityDao.Properties.PDatastate.notEq(SgStrKey.del);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getDPictureEntityDao()
                .queryBuilder()
                .where(eq1, eq3)
                .orderDesc(DPictureEntityDao.Properties.PTime)//降序
                .list();
    }

    //获取最新照片

    /**
     * 获取最新照片
     */
    public static Object get123Zp(String... value) {
        if (value[0].equals(SgStrKey.uuiddh)) {//到货到场最新照片
            List<CArrivalRecordEntity> listAll = new ArrayList<>();
            for (CStackPointEntity pointEntity : getCSpListAll(value[1])) {
                listAll.addAll(getCArListAll(pointEntity.getGuid()));
            }
            if (listAll.isEmpty()) return R.drawable.ic_default_image;
            Collections.sort(listAll, new Comparator<CArrivalRecordEntity>() {
                @Override
                public int compare(CArrivalRecordEntity o1, CArrivalRecordEntity o2) {
                    if (o1.getARTime().getTime() < o2.getARTime().getTime()) {
                        return 1;
                    } else if (o1.getARTime().getTime() == o2.getARTime().getTime()) {
                        return 0;
                    }
                    return -1;
                }
            });
            return getSsUrl(listAll.get(0).getGuid());
        } else if (value[0].equals(SgStrKey.uuidjl)) {//中间检查最新照片
            List<CMiddleCheckEntity> list = getCMceListAll(value[1]);
            if (list == null || list.isEmpty()) return R.drawable.ic_default_image;
            return getYbgcUrl(list.get(0).getGuid());
        }
        return R.drawable.ic_default_image;
    }


    //设备物资查询

    /**
     * 设备物资查询
     */
    public static List<BDeviceEntity> getBDeviceEntityList(int i, String... value) {
        List<BDeviceEntity> list = new ArrayList<>();
        BDeviceEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getBDeviceEntityDao();
        if (i == 0) {//仅依据guid查找
            WhereCondition eq1 = BDeviceEntityDao.Properties.Guid.eq(value[0]);
            list.addAll(entityDao.queryBuilder().where(eq1).list());
        } else if (i == 1) {//依据D_LABEL、D_PARAMETER获取数据
            WhereCondition eq1 = BDeviceEntityDao.Properties.DLabel.eq(value[0]);
            WhereCondition eq2 = BDeviceEntityDao.Properties.DParameter.like("%" + value[1] + "%");
            list.addAll(entityDao.queryBuilder().where(eq1, eq2).list());
        } else if (i == 2) {//获取所有DMidtype并去重
            List<String> list2 = new ArrayList<>();
            WhereCondition eq1 = BDeviceEntityDao.Properties.DInformationType.eq(value[0]);
            List<BDeviceEntity> list1 = entityDao.queryBuilder().where(eq1).list();
            for (BDeviceEntity entity : list1) {
                if (!list2.contains(entity.getDMidtype())) {
                    list2.add(entity.getDMidtype());
                    list.add(entity);
                }
            }
        } else if (i == 3) {//获取所有D_LABEL并去重
            List<String> list2 = new ArrayList<>();
            WhereCondition eq1 = BDeviceEntityDao.Properties.DInformationType.eq(value[0]);
            WhereCondition eq2 = BDeviceEntityDao.Properties.DMidtype.eq(value[1]);
            List<BDeviceEntity> list1 = entityDao.queryBuilder().where(eq1, eq2).list();
            for (BDeviceEntity entity : list1) {
                if (!list2.contains(entity.getDLabel())) {
                    list2.add(entity.getDLabel());
                    list.add(entity);
                }
            }
        }
        return list;
    }


    //材料物资查询

    /**
     * 材料物资查询
     */
    public static List<BMaterialEntity> getBMaterialEntityList(int i, String... value) {
        List<BMaterialEntity> list = new ArrayList<>();
        BMaterialEntityDao entityDao = GreenDaoManager.getInstance().getmDaoSession().getBMaterialEntityDao();
        if (i == 0) {//仅依据guid查找
            WhereCondition eq1 = BMaterialEntityDao.Properties.Guid.eq(value[0]);
            list.addAll(entityDao.queryBuilder().where(eq1)
                    .list());
        } else if (i == 1) {//依据D_LABEL、D_PARAMETER获取数据
            WhereCondition eq1 = BMaterialEntityDao.Properties.MLabel.eq(value[0]);
            WhereCondition eq2 = BMaterialEntityDao.Properties.MParameter.like("%" + value[1] + "%");
            list.addAll(entityDao.queryBuilder().where(eq1, eq2).list());
        } else if (i == 2) {//获取所有MMidtype
            List<String> list2 = new ArrayList<>();
            WhereCondition eq1 = BMaterialEntityDao.Properties.MInformationType.eq(value[0]);
            List<BMaterialEntity> list1 = entityDao.queryBuilder().where(eq1).list();
            for (BMaterialEntity entity : list1) {
                if (!list2.contains(entity.getMMidtype())) {
                    list2.add(entity.getMMidtype());
                    list.add(entity);
                }
            }
        } else if (i == 3) {//获取所有D_LABEL
            List<String> list2 = new ArrayList<>();
            WhereCondition eq1 = BMaterialEntityDao.Properties.MInformationType.eq(value[0]);
            WhereCondition eq2 = BMaterialEntityDao.Properties.MMidtype.eq(value[1]);
            List<BMaterialEntity> list1 = entityDao.queryBuilder().where(eq1, eq2).list();
            for (BMaterialEntity entity : list1) {
                if (!list2.contains(entity.getMMidtype())) {
                    list2.add(entity.getMMidtype());
                    list.add(entity);
                }
            }
        }
        return list;
    }


    //采集时展示的项目进度

    /**
     * 采集时展示的项目进度
     */
    public static List<CScheduleEntity> getScheduleCj(String PGuid) {
        WhereCondition eq1 = CScheduleEntityDao.Properties.PGuid.eq(PGuid);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCScheduleEntityDao()
                .queryBuilder()
                .where(eq1)
                .orderAsc(CScheduleEntityDao.Properties.SSort)
                .list();
    }

    //获取项目全部进度填报信息

    /**
     * 获取项目全部进度填报信息
     */
    public static List<CScheduleReportEntity> getScheduleReportAll(String SGuid) {
        WhereCondition eq1 = CScheduleReportEntityDao.Properties.SGuid.eq(SGuid);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCScheduleReportEntityDao()
                .queryBuilder()
                .where(eq1)
                .orderDesc(CScheduleReportEntityDao.Properties.SRAddtime)//降序
                .list();
    }

    //获取施工进度记录照片/材料到场记录照片/隐蔽工程信息照片

    /**
     * 获取施工进度记录照片/材料到场记录照片/隐蔽工程信息照片
     */
    public static List<DPictureEntity> getPictureAll(String PPGuid) {
//        WhereCondition eq1 = DPictureEntityDao.Properties.PPGuid.eq(PPGuid);
//        List<DPictureEntity> list = GreenDaoManager.getInstance().getmDaoSession()
//                .getDPictureEntityDao()
//                .queryBuilder()
//                .where(eq1)
//                .orderDesc(DPictureEntityDao.Properties.PTime)//降序
//                .list();
        List<DPictureEntity> list = GreenDaoManager.getInstance().getNewSession().getDPictureEntityDao().queryBuilder().where(DPictureEntityDao.Properties.PPGuid.eq(PPGuid))
                .orderDesc(DPictureEntityDao.Properties.PTime).list();
        return list;
    }

    //获取项目全部堆放点

    /**
     * 获取项目全部堆放点
     */
    public static List<CStackPointEntity> getStackPointAll(String PGuid) {
        WhereCondition eq1 = CStackPointEntityDao.Properties.PGuid.eq(PGuid);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCStackPointEntityDao()
                .queryBuilder()
                .where(eq1)
                .list();
    }

    //获取项目全部到货记录

    /**
     * 获取项目全部到货记录
     */
    public static List<CArrivalRecordEntity> getArrivalRecordAll(String SPGuid) {
        WhereCondition eq1 = CArrivalRecordEntityDao.Properties.SPGuid.eq(SPGuid);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCArrivalRecordEntityDao()
                .queryBuilder()
                .where(eq1)
                .orderDesc(CArrivalRecordEntityDao.Properties.ARTime)
                .list();
    }

    //获取项目全部到货物资

    /**
     * 获取项目全部到货物资
     */
    public static List<CGoodsDetailEntity> getGoodsDetailAll(String ARGuid) {
        WhereCondition eq1 = CGoodsDetailEntityDao.Properties.ARGuid.eq(ARGuid);
        WhereCondition eq2 = CGoodsDetailEntityDao.Properties.GDDatastate.notEq(SgStrKey.ytb);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCGoodsDetailEntityDao()
                .queryBuilder()
                .where(eq1, eq2)
                .orderDesc(CGoodsDetailEntityDao.Properties.GDPrice)
                .list();
    }

    //获取项目全部中间检查记录

    /**
     * 获取项目全部中间检查记录
     */
    public static List<CMiddleCheckEntity> getMiddleCheckAll(String PGuid) {
        WhereCondition eq1 = CMiddleCheckEntityDao.Properties.PGuid.eq(PGuid);
        WhereCondition eq2 = CMiddleCheckEntityDao.Properties.MCDatastate.notEq(SgStrKey.ytb);
        return GreenDaoManager.getInstance().getmDaoSession()
                .getCMiddleCheckEntityDao()
                .queryBuilder()
                .where(eq1, eq2)
                .orderDesc(CMiddleCheckEntityDao.Properties.MCTime)//降序
                .list();
    }


    //------------------new------------------//
}
